<template>
    <div>
        <h1>graphemer-test</h1>
        <div>
            原字符串：{{str}}
        </div>
    </div>
</template>

<script setup>
import Graphemer from 'graphemer';
const sp = new Graphemer();

function splitKeepSpaces(str) {
  return str
    .split(/(\p{White_Space}+)/gu)        // 捕获任意 Unicode 空白
    .flatMap(block => sp.splitGraphemes(block)); // 防止 Emoji/连字被劈断
}
function splitWord(str) {
  return str
    .split(/(\p{White_Space}+)/gu) 
}
const str = 'hello 111111 111hello11111 absbdabasdbasbdbas  word! 你好老师。.. 你好，老师  你好老师。..你好，老师。  world!\n👨🏽‍🚀 　'
const res0 = splitWord(str)
console.log('res0',res0)
const res1 = splitKeepSpaces(str)
console.log('res1',res1)
const res2 = sp.splitGraphemes(str)
console.log('res2',res2)
</script>